<template>
  <div class="container">
    <div class="content-container">
      <template v-if="modType === 'TST' || modType === 'DXT'">
        <p>{{ $t("mod_test_times") }}：{{ maxUsrAttempt === 0 ? $t("mod_test_unlimit") : maxUsrAttempt }}</p>
        <p>{{ $t("mod_test_open_times") }}：{{ maxUsrOpen === 0 ? $t("mod_unlimit") : maxUsrOpen }}</p>
        <p>{{ $t("mod_total_score") }}：{{maxScore ? maxScore : 0}}</p>
        <p>{{ $t('mod_best_score')}}：{{movMaxScore ? movMaxScore : 0}}</p>
        <p>{{ $t("mod_pass_rate") }}：{{passScore ? passScore : 0}}%</p>
        <p>{{ $t("mod_time_limit_requirement") }}：{{modRequiredTime}}{{$t("mod_time_minute") }}</p> <!--限时时间-->
      </template>
      <p v-if="modType !== 'COURSE'">{{ $t('mod_last_access_time')}}： {{submitTime}}</p> <!--最近一次访问时间-->
      <p>{{ $t("mod_status") }}：{{ getAppStatusStr(movStatus,modType )  }}</p><!--状态-->
      <p>{{ $t('mod_study_duration')}}：{{ beginTime | substringTime }} {{ $t("time_to") }} {{ endTime === '9999-12-31 23:59:59' ? $t("cos_unlimited") : endTime }}</p><!--学习时间-->
      <p ><span v-if="modType == 'ACE'">{{ item.modSubmitType==='REALNAME' ?$t("mod_submit_type")+":"+$t('real_name_submitted') :$t("mod_submit_type")+":"+ $t('anonymous_submission')}}</span></p>
      <template v-if="modType === 'ACE'|| modType === 'SVY' || modType === 'ASS'">
        <p>{{ $t("mod_submit_time") }}：{{lastTime | conversionTime }}</p>
      </template>
      <!--测验报告-->
      <template v-if="modType === 'TST' || modType === 'DXT'">
        <p class="word-btn-01 box-padding-03" v-if="submitTime" @click="JumpTestingReport()">{{ $t("exam_report") }}</p><!--测验报告-->
      </template>
    </div>
  </div>
</template>

<script>
export default {
    name: 'courseExhibition',
    data() {
        return {
            dto: null,
            maxUsrOpen: 0,
            maxUsrAttempt: 0,
            maxScore: 0,
            movMaxScore: 0,
            passScore: 0,
            modRequiredTime: this.item.modRequiredTime ? this.item.modRequiredTime / 60 : '--',
            modType: this.item.nodeType === 4 ? 'COURSE' : this.item.modType, // 如果nodeType为4则为课程
            submitTime: this.item.submitTime,
            movStatus: this.item.nodeType === 4 ? this.item.itmStatus : this.item.movStatus,
            beginTime: this.item.nodeType === 4 ? this.item.itmContentEffStartDatetime : this.item.beginTime,
            endTime: this.item.nodeType === 4 ? this.item.itmContentEffEndDatetime : this.item.endTime,
            lastTime: this.item.lastTime
        };
    },
    props: {
        item: {
            type: Object,
            default: () => {}
        }
    },
    methods: {
        getAppStatusStr(movStatus, type) { //每个学习单元的状态
            if (!movStatus) return this.$t('lab_tip_7');
            if (movStatus === 'I') {
                if ((type === 'ASS' || type === 'TST' || type === 'DXT') && this.submitTime) {
                    return this.$t('cos_app_G'); //评分中
                } else if (type === 'VOD' || type === 'RDG' || type === 'FAQ' || type === 'GLO' || type === 'REF' || type === 'AUD') {
                    return this.$t('cos_app_I_V'); //已查阅
                } else {
                    return this.$t('cos_app_inprogress'); //进行中
                }
            } else if (movStatus === 'N') {
                return this.$t('cos_app_N_scorm'); //未尝试
            } else if (movStatus === 'C' && (type === 'SVY' || type === 'ACE')) {
                return this.$t('cos_app_S'); //已提交
            } else if (movStatus === 'C') {
                return this.$t('cos_app_completed'); //已完成
            } else if (movStatus === 'F') {
                if (type === 'TST' || type === 'DXT' || type === 'ASS') {
                    return this.$t('cos_app_flunk'); //fail,不合格
                } else {
                    return this.$t('cos_app_fail'); //fail,未完成
                }
            } else if (movStatus === 'B') {
                return this.$t('cos_app_B_scorm');
            } else if (movStatus === 'P') {
                if (type === 'TST' || type === 'DXT' || type === 'ASS') {
                    return this.$t('cos_app_passed'); //passed,已合格
                } else {
                    return this.$t('cos_app_P'); //pass,已通过
                }
            } else if (movStatus === 'W') {
                return this.$t('cos_app_withdrawn'); //已放弃
            } else if (movStatus === 'notapp') {
                return this.$t('cos_app_notapp'); //未报名
            } else if (movStatus === 'pending') {
                return this.$t('cos_app_pending'); //审批中
            } else if (movStatus === 'admitted') {
                return this.$t('cos_app_admitted'); //已报名
            } else if (movStatus === 'rejected') {
                return this.$t('cos_app_admitted'); //已报名
            } else if (movStatus === 'waiting') {
                return this.$t('cos_in_wait_list'); //等待队列
            } else {
                return this.$t('cos_app_notapp'); //未报名
            }
        },
        testReportBtn() { //测试报告
            if (this.submitTime && this.submitTime !== '') {
                return true;
            }
        },
        JumpTestingReport() {
            let attemptNbr = this.item.traineeTestDetailDTO.attemptNbr || 0;
            this.$router.push({path: `/testingReport/${this.item.itmId}/${this.item.tkhId}/${this.item.moduleId}?attemptNbr=${attemptNbr}`});
        },
        /**
         * 变量初始化值后, 父页面传值将不会动态改变
         */
        toRender(item) {
            this.dto = item;
            this.modRequiredTime = item.modRequiredTime ? item.modRequiredTime / 60 : '--';
            this.modType = item.nodeType === 4 ? 'COURSE' : item.modType; // 如果nodeType为4则为课程
            this.submitTime = item.submitTime || '--';
            this.movStatus = item.nodeType === 4 ? item.itmStatus : item.movStatus;
            this.beginTime = item.nodeType === 4 ? item.itmContentEffStartDatetime : item.beginTime;
            this.endTime = item.nodeType === 4 ? item.itmContentEffEndDatetime : item.endTime;
            this.lastTime = item.lastTime;
        }
    },
    mounted() {
        if (this.item.traineeTestDetailDTO) {
            this.maxScore = this.item.traineeTestDetailDTO.maxScore;
            this.passScore = this.item.traineeTestDetailDTO.passScore;
            this.maxUsrOpen = this.item.traineeTestDetailDTO.maxUsrOpen;
            this.maxUsrAttempt = this.item.traineeTestDetailDTO.maxUsrAttempt;
            this.movMaxScore = this.item.traineeTestDetailDTO.movMaxScore;
        }
        this.toRender(this.item);
    },
    watch: {
        item: function(newValue, oldValue) {
            this.toRender(newValue);
        }
    }
};
</script>

<style scoped lang="less">
 .container{
   background-color: #f3f3f3;
   .content-container{
     padding: 20px;
     display: flex;
     flex-direction: column;
     >p{
       font-size: 14px;
     }
   }
 }
</style>
